package com.carrot.uaa.app;

import com.carrot.uaa.domain.IAuthBusinessRuleService;
import com.carrot.uaa.entity.OAuth2User;
import com.carrot.uaa.infrastructure.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * OAuth2自定义用户查询实现
 */
@Service
@RequiredArgsConstructor
public class OAuth2UserDetailsAppServiceImpl implements UserDetailsService {

    private final UserService userService;

    private final IAuthBusinessRuleService iAuthBusinessRuleService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        //获取账号
        OAuth2User userByAccount = userService.getUserByAccount(username);
        //账号校验
        iAuthBusinessRuleService.checkAccount(userByAccount);
        return userByAccount;
    }

}
